<%= render layout: "layouts/decidim/shared/layout_center" do %>
  <div class="flex justify-center">
    <h1 class="title-decorator my-12">
      <%= t("wants_to_use_your_account_html", scope: "decidim.doorkeeper.authorizations.new", application_name: oauth_application.name) %>
      <%= t("by_organization_link_html", scope: "decidim.doorkeeper.authorizations.new", link: link_to(oauth_application.organization_name, oauth_application.organization_url)) %>
    </h1>
  </div>

  <div class="login__info">
    <p>
      <%= t("connect_your_account_html", scope: "decidim.doorkeeper.authorizations.new", organization: current_organization_name) %>
    </p>

    <p><%= t("this_application_will_be_able_to", scope: "decidim.doorkeeper.authorizations.new") %></p>
    <ul class="list-disc ml-4">
      <% if @scopes.include?("profile") || @scopes.include?("user") %>
        <li><%= t("see_name", scope: "decidim.doorkeeper.authorizations.new") %></li>
        <li><%= t("see_username", scope: "decidim.doorkeeper.authorizations.new") %></li>
        <li><%= t("see_email", scope: "decidim.doorkeeper.authorizations.new") %></li>
      <% end %>
      <% if @scopes.include?("user") %>
        <li><%= t("update_profile", scope: "decidim.doorkeeper.authorizations.new") %></li>
      <% end %>
      <% if @scopes.include?("api:read") %>
        <li><%= t("api_read", scope: "decidim.doorkeeper.authorizations.new") %></li>
      <% end %>
      <% if @scopes.include?("api:write") %>
        <li><%= t("publish_content", scope: "decidim.doorkeeper.authorizations.new") %></li>
      <% end %>
    </ul>

    <% unless all_abilities? %>
      <p><%= t("this_application_will_not_be_able_to", scope: "decidim.doorkeeper.authorizations.new") %></p>
      <ul class="list-disc ml-4">
        <% if !@scopes.include?("profile") && !@scopes.include?("user") %>
          <li><%= t("see_name", scope: "decidim.doorkeeper.authorizations.new") %></li>
          <li><%= t("see_username", scope: "decidim.doorkeeper.authorizations.new") %></li>
          <li><%= t("see_email", scope: "decidim.doorkeeper.authorizations.new") %></li>
        <% end %>
        <% unless @scopes.include?("user") %>
          <li><%= t("update_profile", scope: "decidim.doorkeeper.authorizations.new") %></li>
        <% end %>
        <% unless @scopes.include?("api:read") %>
          <li><%= t("api_read", scope: "decidim.doorkeeper.authorizations.new") %></li>
        <% end %>
        <% unless @scopes.include?("api:write") %>
          <li><%= t("publish_content", scope: "decidim.doorkeeper.authorizations.new") %></li>
        <% end %>
      </ul>
    <% end %>
  </div>

  <div class="form__wrapper-block flex-col-reverse md:flex-row justify-between">
    <%= form_tag oauth_authorization_path, method: :delete do %>
      <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
      <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
      <%= hidden_field_tag :state, @pre_auth.state %>
      <%= hidden_field_tag :response_type, @pre_auth.response_type %>
      <%= hidden_field_tag :response_mode, @pre_auth.response_mode, id: nil %>
      <%= hidden_field_tag :scope, @pre_auth.scope %>
      <%= hidden_field_tag :code_challenge, @pre_auth.code_challenge, id: nil %>
      <%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method, id: nil %>

      <button type="submit" class="button button__lg button__transparent-secondary">
        <span><%= t("cancel", scope: "decidim.doorkeeper.authorizations.new") %></span>
      </button>
    <% end %>

    <%= form_tag oauth_authorization_path, method: :post do %>
      <%= hidden_field_tag :client_id, @pre_auth.client.uid %>
      <%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri %>
      <%= hidden_field_tag :state, @pre_auth.state %>
      <%= hidden_field_tag :response_type, @pre_auth.response_type %>
      <%= hidden_field_tag :response_mode, @pre_auth.response_mode, id: nil %>
      <%= hidden_field_tag :scope, @pre_auth.scope %>
      <%= hidden_field_tag :code_challenge, @pre_auth.code_challenge, id: nil %>
      <%= hidden_field_tag :code_challenge_method, @pre_auth.code_challenge_method, id: nil %>

      <button type="submit" class="button button__lg button__secondary">
        <span><%= t("authorize", scope: "decidim.doorkeeper.authorizations.new") %></span>
        <%= icon "arrow-right-line", class: "fill-current" %>
      </button>
    <% end %>
  </div>
<% end %>
